import 'package:gold/generated/json/base/json_convert_content.dart';
import 'dart:convert';

class ListModel<S> {
	int? currentPage;
	List<S>? list;
	String? firstPageUrl;
	dynamic from;
	int? lastPage;
	String? lastPageUrl;
	String? nextPageUrl;
	String? path;
	int? perPage;
	String? prevPageUrl;
	dynamic to;
	int? total;
	int? count;
	int? totalPages;

	ListModel();

	factory ListModel.fromJson(Map<String, dynamic> json) {
		final ListModel<S> listModel = ListModel<S>();
		final int? currentPage = jsonConvert.convert<int>(json['current_page']);
		if (currentPage != null) {
			listModel.currentPage = currentPage;
		}
		final String? firstPageUrl = jsonConvert.convert<String>(json['first_page_url']);
		if (firstPageUrl != null) {
			listModel.firstPageUrl = firstPageUrl;
		}
		final dynamic from = json['from'];
		if (from != null) {
			listModel.from = from;
		}
		final int? lastPage = jsonConvert.convert<int>(json['last_page']);
		if (lastPage != null) {
			listModel.lastPage = lastPage;
		}
		final String? lastPageUrl = jsonConvert.convert<String>(json['last_page_url']);
		if (lastPageUrl != null) {
			listModel.lastPageUrl = lastPageUrl;
		}
		final String? nextPageUrl = json['next_page_url'];
		if (nextPageUrl != null) {
			listModel.nextPageUrl = nextPageUrl;
		}
		final String? path = jsonConvert.convert<String>(json['path']);
		if (path != null) {
			listModel.path = path;
		}
		final int? perPage = jsonConvert.convert<int>(json['per_page']);
		if (perPage != null) {
			listModel.perPage = perPage;
		}
		final String? prevPageUrl = json['prev_page_url'];
		if (prevPageUrl != null) {
			listModel.prevPageUrl = prevPageUrl;
		}
		final dynamic to = json['to'];
		if (to != null) {
			listModel.to = to;
		}
		final int? total = jsonConvert.convert<int>(json['total']);
		if (total != null) {
			listModel.total = total;
		}
		final int? count = jsonConvert.convert<int>(json['count']);
		if (total != null) {
			listModel.count = count;
		}
		final int? totalPages = jsonConvert.convert<int>(json['total_pages']);
		if (total != null) {
			listModel.totalPages = totalPages;
		}
		final List<dynamic>? list = jsonConvert.convert<List<dynamic>>(json['data']);
		if (list != null) {
			listModel.list = list.map((element) {
				final func = JsonConvert().convertFuncMap[S.toString()];
				if (func != null) {
					return func.call(element) as S;
				} else {
					return element as S;
				}
			}).toList();
		}
		return listModel;
	}

	Map<String, dynamic> toJson() {
		final Map<String, dynamic> data = <String, dynamic>{};
		data['current_page'] = currentPage;
		data['data'] = list?.map((v) => v.toString()).toList();
		data['first_page_url'] = firstPageUrl;
		data['from'] = from;
		data['last_page'] = lastPage;
		data['last_page_url'] = lastPageUrl;
		data['next_page_url'] = nextPageUrl;
		data['path'] = path;
		data['per_page'] = perPage;
		data['prev_page_url'] = prevPageUrl;
		data['to'] = to;
		data['total'] = total;
		data['count'] = count;
		data['total_pages'] = totalPages;
		return data;
	}

	@override
	String toString() {
		return jsonEncode(this);
	}
}